package com.company.cloud.product.modules.mgr.utils;

import java.util.List;
import java.util.Map;

import org.springframework.util.CollectionUtils;

import com.company.cloud.product.modules.base.entity.ComeOrder;
import com.company.cloud.product.modules.base.entity.ComeOrderItem;
import com.company.cloud.product.modules.base.entity.OutOrder;
import com.company.cloud.product.modules.base.entity.OutOrderItem;
import com.company.cloud.product.modules.mgr.models.ComeItemModel;
import com.company.cloud.product.modules.mgr.models.ComeModel;
import com.company.cloud.product.modules.mgr.models.OutItemModel;
import com.company.cloud.product.modules.mgr.models.OutModel;

public class ProductConvertUtils {

	
	/**出库单*/
	public static OutModel getOutModel(OutOrder order,List<OutOrderItem> orderItems) {
		OutModel model=new OutModel();
		model.setSn(order.getSn());
		model.setCustNo(order.getCustNo());
		model.setOrderDate(order.getOrderDate());
		model.setMemo(order.getMemo());
		model.setOpUserId(order.getCman());
//		model.setOpUserName();
		
		if(!CollectionUtils.isEmpty(orderItems)) {
			orderItems.forEach(item->{
				if(order.getSn().equals(item.getOutSn())) {
					OutItemModel modelItem=new OutItemModel(item.getId(), 
							item.getOutSn(), item.getProductNo(),item.getSkuNo() , item.getQuantity(),
							item.getName(),item.getThumbnail(),item.getSpecifications()
							);
					model.addItem(modelItem);
				}
			});
		}
		
		return model;
	}
	
	/**入库单*/
	public static ComeModel getComeModel(ComeOrder order,List<ComeOrderItem> orderItems) {
		ComeModel model=new ComeModel();
		model.setSn(order.getSn());
		model.setCustNo(order.getCustNo());
		model.setOrderDate(order.getOrderDate());
		model.setMemo(order.getMemo());
		model.setOpUserId(order.getCman());
//		model.setOpUserName();
		if(!CollectionUtils.isEmpty(orderItems)) {
			orderItems.forEach(item->{
				if(order.getSn().equals(item.getComeSn())) {
					ComeItemModel modelItem=new ComeItemModel(item.getId(), 
							item.getComeSn(), item.getProductNo(), item.getSkuNo(), item.getQuantity(),
							item.getName(),item.getThumbnail(),item.getSpecifications()
							);
					model.addItem(modelItem);
				}
			});
		}
		return model;
	}
	
	
	
}
